<template>
  <div>
    <div style="height:50px;line-height:50px;background:#eee">
      <span class="iconfont icon-left" style="padding:0 10px" @click="$router.go(-1)"></span>
      <span>修改用户名</span>
    </div>
    <div>
      <van-cell-group>
        <van-field v-model="newName" type="text" label="昵称" placeholder="新名称" required />
      </van-cell-group>
    </div>
    <van-button @click="changeName()" block type="primary" style="position:absolute;bottom:0">确定</van-button>
  </div>
</template>
<script>
export default {
  data: () => ({
    newName: null
  }),
  methods: {
    changeName() {
      if (this.newName) {
        let data = {
          username: this.newName
        };
        this.$axios
          .post(`ym/memberuser/member-modify-username`, data)
          .then(res => {
            if (res.data.code === 0) {
              this.$Toast("修改成功");
              this.$router.go(-1);
            } else {
              this.$Toast(res.data.msg);
            }
            console.log(res);
          });
      }else{
        this.$Toast('新名称不能为空！')
      }
    }
  }
};
</script>
<style lang="scss" scoped>
</style>